<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>微信回调页面</title>
    <script type="text/javascript" src="script/jquery-1.8.0.min.js"></script>
    <script src="plugins/axios/dist/axios.js"></script>
    <script src="plugins/vue/dist/vue.js"></script>
    <script src="js/common.js"></script>
</head>
<body>
<div id="heart">
<script type="text/javascript">
    new Vue({
        el:"#heart",
        data:{},
        methods:{
            getVxInfo(paramObj){
                let requestObj={code:paramObj.code};
                this.$http.post("/logininfo/wechat/login",requestObj)
                          .then(result=>{
                              result=result.data;
                              if (result.success){
                                  alert("登录成功！")
                                  let{token,loginInfo}=result.object;
                                  localStorage.setItem('loginInfo', JSON.stringify(loginInfo)); //登录信息，前端展示
                                  localStorage.setItem('token', token); //这是后端生成的返回的随机码，用来放在请求头上的，判断用户时候登录
                                  location.href="/index.html"
                              }
                                  if (!result.success && result.message == "goBind") {
                                      alert("微信绑定！")
                                      let {accessToken, openid} = result.object;
                                      location.href = "/binder.html?accessToken=" + accessToken + "&openid=" + openid;
                                  }
                                 else {
                                      alert("登录失败！"+result.message)

                              }
                          })
                           .catch(result=>{
                               alert("登录失败！"+result.message)
                           })
            },
        },
        mounted(){
            var url = location.href;
            var paramObj = parseParamObj(url);
         //发起请求到后端
            this.getVxInfo(paramObj);
        }
    })
</script>
</div>
</body>
</html>